package com.baiyangtx.lingerweather.model;

import java.util.Map;

import com.baiyangtx.lingerweather.R;
import com.baiyangtx.lingerweather.adapt.CityKey;

import android.content.Context;
import android.graphics.drawable.Drawable;

public class CityBasicImformationAdapt implements CityBasicImformation {
	
	private Context context ;
	
	private String code ;
	
	private String name ;
	
	private int temperature ;
	
	private String weather ;
	
	public CityBasicImformationAdapt(Context context , Map<String, String> city) {
		this.context = context ;
		code = city.get(CityKey.CITY_CODE) ;
		name = city.get(CityKey.CITY_NAME) ;
		String temp = city.get( CityKey.REAL_TEMPERATURE ) ;
		if( temp == null ){
			temperature = 0 ;
			weather = CityKey.WEATHER_SUNNY ;
		}else{
			try{
				temperature = Integer.valueOf(temp) ;
			}catch(Throwable t){
				temperature = 0 ;
			}
			weather = city.get( CityKey.RECENT_WEATHER ) ;
		}
	}
	
	
	@Override
	public String getCityId() {
		return code ;
	}

	@Override
	public String getCityName() {
		return name ;
	}

	@Override
	public int getCityTemperature() {
		return temperature ;
	}

	@Override
	public Drawable getCityWeather() {
		return parserWeatherDrawable(weather) ;
	}
	
	private Drawable parserWeatherDrawable(String key){
		int weather  = 0 ;

		if( key.equals(CityKey.WEATHER_CLOUDY )){
			weather = R.drawable.cloudy ;
		}else if(key.equals(CityKey.WEATHER_OVERCAST )) {
			weather = R.drawable.overcast ;
		}else if(key.equals(CityKey.WEATHER_SUNNY )) {
			weather = R.drawable.sunny ;
		}else if(key.equals(CityKey.WEATHER_WINDY )) {
			weather = R.drawable.windy ;
		}else if(key.equals(CityKey.WEATHER_FOG )) {
			weather = R.drawable.fog ;
		}else if(key.equals(CityKey.WEATHER_HARD_RAIN )) {
			weather = R.drawable.hard_rain ;
		}else if(key.equals(CityKey.WEATHER_HEAVY_RAIN )) {
			weather = R.drawable.heavy_rain ;
		}else if(key.equals(CityKey.WEATHER_HEAVY_SNOW )) {
			weather = R.drawable.heavy_snow ;
		}else if(key.equals(CityKey.WEATHER_LIGHT_RAIN )) {
			weather = R.drawable.light_rain ;
		}else if(key.equals(CityKey.WEATHER_LIGHT_SNOW )) {
			weather = R.drawable.light_snow ;
		}
		
		return context.getResources().getDrawable(weather) ;
	}

}
